package com.tsl.prevention.modules.user.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tsl.prevention.modules.user.entity.Servicerecord;
import com.tsl.prevention.modules.user.service.IServicerecordService;
import com.tsl.prevention.util.Result;
import com.tsl.prevention.util.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lionel
 * @since 2021-03-24
 */
@RestController
@RequestMapping("/user/servicerecord")
@Api
public class ServicerecordController {
    @Autowired
    private IServicerecordService iServicerecordService;

    @PostMapping("/addServiceRecord")
    @ApiOperation("/创建订单")
    public Result addServiceRecord(@RequestBody Servicerecord servicerecord) {
        servicerecord.setId(StringUtil.getGUID());
        boolean save = iServicerecordService.save(servicerecord);
        return Result.create(servicerecord);
    }

    @GetMapping("/getListByState")
    @ApiOperation("查询列表")
    public Result getList(String openId,String state) {
        List<HashMap<String ,String>> list =  iServicerecordService.getList(openId,state);
//        List<Servicerecord> list = iServicerecordService.list(new QueryWrapper<Servicerecord>().eq("user_id",openId));
        return Result.create(list);
    }
    //修改订单状态'
    @PostMapping("/updateRecord")
    @ApiOperation("修改订单状态")
    public Result updateRecord(String recordId,Integer state) {
        Servicerecord servicerecord = new Servicerecord();
        servicerecord.setId(recordId);
        servicerecord.setState(state);
        iServicerecordService.updateById(servicerecord);
        return Result.create();
    }
    @DeleteMapping("/delRecord/{id}")
    @ApiOperation("/删除订单")
    public Result delRecord(@PathVariable(value = "id") String id) {
        iServicerecordService.removeById(id);
        return Result.create();
    }

    @GetMapping("/getRecord")
    @ApiOperation("根据id获取订单")
    public Result getRecord(String id) {
        HashMap<String,String> map = iServicerecordService.getRecord(id);
        return Result.create(map);
    }


}

